<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Model\User;
use Hash;

class LoginController extends Controller
{
    //加载后台登陆视图
 public function login()
 {
 	return view('login.login');
 }

 public function postLogin(Request $request)
 {
 	
 	//数据库检测登陆者是否存在
 	$user = User::where('email',$request->email)->first();

 	$userpass = Hash::make($user->password);

 	//检测密码是否一致
 	if(Hash::check($user->password,$userpass)){
 		session(['user'=>$user]);
 		return redirect('/adminIndex');
 	}else{
 		return back();
 		
 	}

 }

 //执行退出
 public function logout()
 {
 	session()->forget('user');
 	return redirect('/login');
 }

}
